package com.Glow.reggie.controller;

import com.Glow.reggie.common.BaseContext;
import com.Glow.reggie.common.R;
import com.Glow.reggie.entity.Orders;
import com.Glow.reggie.service.OrdersService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author Glow
 * @Date 2022-08-05 21:25:56
 * @Description 支付订单Order
 * @Version 1.0
 */
@RestController
@RequestMapping("order")
public class OrderController {
    @Autowired
    private OrdersService ordersService;

    /**
     * 订单下单
     * @param orders
     * @return
     */
    @PostMapping("submit")
    public R<String> submit (@RequestBody Orders orders)
    {
        ordersService.submit(orders);
        return R.success("提交订单成功！");
    }
    @GetMapping("userPage")
    public R<Page> page(int page,int pageSize)
    {
        Page<Orders> pageInfo = new Page<>();
        LambdaQueryWrapper<Orders> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Orders::getUserId, BaseContext.getCurrentId());
        ordersService.page(pageInfo,queryWrapper);
        return R.success(pageInfo);
    }
}
